package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsOrder;
import com.qf.service.DtsOrderService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("admin/order")
public class DtsAdminOrderController {
    @Autowired
    DtsOrderService orderService;

    @RequestMapping("/ship")
    public Object ship(@RequestBody Map<String,Object> map){
        Integer orderId = (Integer) map.get("orderId");
        String shipChannel = (String) map.get("shipChannel");
        String shipSn = (String) map.get("shipSn");
        orderService.ship(orderId,shipChannel,shipSn);
        return ResponseUtil.ok();
    }

    @RequestMapping("/detail")
    public Object detail(Integer id){
        Map<String,Object> data=orderService.finddetial(id);
        return ResponseUtil.ok(data);
    }

    @RequestMapping("/listShipChannel")
    public Object listShipChannel(){
        List<Map<String,Object>> maps=orderService.findlistShipChannel();
        Map<String,Object> data = new HashMap<>();
        data.put("shipChannelList",maps);
        return ResponseUtil.ok(data);
    }

    @RequestMapping("/list")
    public Object list(@RequestParam(name = "page",required = false,defaultValue = "1") Integer page,
                       @RequestParam(name = "limit",required = false,defaultValue = "20")Integer limit,
                       String sort, String order, Integer orderStatusArray, Integer userId,Integer orderSn){
        IPage<DtsOrder> iPage =orderService.findByPage(page,limit,sort,order,orderStatusArray,userId,orderSn);
        Map<String,Object> data = new HashMap<>();
        data.put("total",iPage.getTotal());
        data.put("items",iPage.getRecords());
        return ResponseUtil.ok(data);
    }
}
